package com.kjzy.mapper;

import com.kjzy.pojo.Member;
import com.kjzy.pojo.Reservation;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;
@Mapper
public interface ReservationMapper {
    @Select("select * from resion_jiangsheng where id=#{id}")
    Reservation findById(@Param("id") int id);
    @Delete("delete from resion_jiangsheng where id=#{id}")
    int deleteReservation(@Param("id") int id);
    @SelectProvider(type = ReservationSqlBuilder.class,method = "buildFindAllR")
    List<Reservation> findAllM(Reservation reservation);

    class ReservationSqlBuilder{
        public static String buildFindAllR(final Reservation reservation){
            return new SQL(){{
                SELECT("*");
                FROM("resion_jiangsheng");
                if (reservation.getId()!=null && !reservation.getId().equals("")){
                    WHERE("id=#{id}");
                }
                if (reservation.getUsername()!=null && !reservation.getUsername().equals("")){
                    WHERE("username LIKE CONCAT('%', #{username}, '%')");
                }
                if (reservation.getProjecot()!=null && !reservation.getProjecot().equals("")){
                    WHERE("projecot LIKE CONCAT('%', #{projecot}, '%')");
                }
            }}.toString();
        }
    }
}
